<template>
  <div style="text-align: left">患者信息:
    <span style="font-size: 16px;background-color: beige;color: #42b983">
      姓名:{{ info.realName }}
      病历号:{{ info.caseNumber }}
      年龄:{{ info.age }}
      性别:{{ info.sex }}

    </span>
  </div>
  <hr/>
  检查项目
  <el-table :data="noMedicalList" style="width: 100%">

    <el-table-column prop="techCode" label="检查编码"/>
    <el-table-column prop="techName" label="检查名称"/>
    <el-table-column prop="techFormat" label="检查规格"/>
    <el-table-column prop="techPrice" label="单价"/>
    <el-table-column prop="priceType" label="费用类型"/>

  </el-table>
  <hr/>
  <div style="text-align: left">
    确认检查医生和科室
    <el-form :inline="true"  class="demo-form-inline" :model="formNoCheck">

      <el-form-item label="检查科室" >
        <el-select placeholder="请选择" v-model="formNoCheck.departId" style="width: 200px">
          <el-option v-for="item in departList" :label="item.deptName"
                     :value="item.id" :key="item.id"></el-option>



          </el-select>
      </el-form-item>
      <el-form-item label="检查医生">
        <el-select placeholder="请选择" v-model="formNoCheck.empId" style="width: 200px">
          <el-option v-for="opt in empList" :label="opt.realname	"
                     :value="opt.id" :key="opt.id"></el-option>
        </el-select>
      </el-form-item>
      <hr/>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">开始检查</el-button>
        <el-button>重置医生</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script setup>
//定义病人信息数据
import {onMounted, reactive, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
//定义病人信息
const info = reactive({
  realName: '',
  caseNumber: '',
  age: '',
  sex: ''
});


const empList = ref([]);
//定义集合保存科室列表
const departList = ref([]);
//定义分配科室和医生的表单
const formNoCheck = reactive({
  departId:'',
  empId:''
});
//定义某个病人某个检查项
const noMedicalList=ref([]);
onMounted(()=>{
  getEmployee();
  getDepartment();
  getRegisterInfo();
  getCheckItem();
});

/*定义函数发生ajax请求获得医生数据*/
function getEmployee() {
  axios.get("http://localhost/his/initEmployee")
      .then((response) => {
        console.log(response.data)
        empList.value = response.data;

      })
      .catch((error) => {
        console.log(error);
      });
}

/*定义函数发生ajax请求，加载科室数据*/
function getDepartment() {
  axios.get("http://localhost/his/initDepartment")
      .then((response) => {
        console.log(response.data)
        departList.value = response.data;

      })
      .catch((error) => {
        console.log(error);
      });
}

//页面加载获得sessionStorage中的病历id和检查项id
let item = sessionStorage.getItem("id");
let json = JSON.parse(item);


/*加载患者信息*/
function getRegisterInfo(){

  axios.get("http://localhost/his/queryRegiserInfo/"+json.id)
      .then((response)=>{
        info.realName=response.data.realName;
        info.caseNumber=response.data.caseNumber;
        info.age=response.data.age;
        info.sex=response.data.gender	;
        //删除sessionStorage对象中保存的键值对

      })
      .catch((error)=>{
        console.log(error);
      });
}
/*
* 发送ajax请求，加载检查信息
* */
function getCheckItem(){
  axios.get("http://localhost/his/queryCheckItem?id="+json.cid)
      .then((response)=>{
        noMedicalList.value=response.data;
        //删除sessionStorage对象中保存的键值对

      })
      .catch((error)=>{
        console.log(error);
      });
}
/*定义函数提交开始检查的ajax请求*/
function onSubmit(){
  axios.get("http://localhost/his/startCheckRecord?id="
      +json.cid+"&empId="+formNoCheck.empId)
      .then((response)=>{
          ElMessage(response.data.msg);
      })
      .catch((error)=>{
        console.log(error);
      });
}
</script>

<style scoped>

</style>